package controller;


import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.junit.Test;

import javax.servlet.http.HttpServlet;
import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;

public class servlet extends HttpServlet {
    public static void main(String[] args) throws Exception{
        //run();

    }
    public static void run() throws Exception{
        String str = "insert into clothes(cloth_name,cloth_price,cloth_color,cloth_address,cloth_number,cloth_path) values(?,?,?,?,?,?)";
        Connection connection = DBUtils.Connection();
        PreparedStatement preparedStatement = connection.prepareStatement(str);
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read("src/main/java/controller/find.xml");
        Element element = document.getRootElement();
        List<Element> list = element.elements();

        for (Element element1:list){
            String cloth_name = element1.element("cloth_name").getStringValue();
            String cloth_price = element1.element("cloth_price").getStringValue();
            String cloth_color = element1.element("cloth_color").getStringValue();
            String cloth_address = element1.element("cloth_address").getStringValue();
            String cloth_number = element1.element("cloth_number").getStringValue();
            String cloth_path = element1.element("cloth_path").getStringValue();
            preparedStatement.setString(1,cloth_name);
            preparedStatement.setString(2,cloth_price);
            preparedStatement.setString(3,cloth_color);
            preparedStatement.setString(4,cloth_address);
            preparedStatement.setString(5,cloth_number);
            preparedStatement.setString(6,cloth_path);
            preparedStatement.executeUpdate();

        }
    }






}